<?php

class Application_Model_LogMapper
{
    // activity report
    protected $_dbTable;

    public function setDbTable($dbTable)
    {
        if (is_string($dbTable)) {
            $dbTable = new $dbTable();
        }
        if (!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception('Invalid table data gateway (logMapper)');
        }
        $this->_dbTable = $dbTable;

        return $this;
    }

    public function getDbTable()
    {
        if (null === $this->_dbTable) {
            $this->setDbTable('Application_Model_DbTable_Log');
        }

        return $this->_dbTable;
    }

    public function save(Application_Model_Log $log)
    {
        $data = array(
            'idPartner' => $log->getIdPartner(),
            'url' => $log->getUrl(),
            'params' => $log->getParams(),
        );
        if ( get_magic_quotes_gpc() ) {
            $data = Application_Model_HomeStrip::strip($data);
        }
        $this->getDbTable()->insert($data);

        return $this->getDbTable()->getAdapter()->lastInsertId();
    }
}